#include<iostream>
#include<cstdio>
#include<sys/types.h>
#include<sys/stat.h>
#include<cstring>
#include<errno.h>
#include<unistd.h>
 #include <fcntl.h>

using namespace std;

#define Mode 0666 //指定命名管道的权限
#define Path "./fifo" //路径名

class Fifo
{
public:
    Fifo(const string& path) 
        :_path(path)
    {
        umask(0);
        int n = mkfifo(Path, Mode); //创建命名管道
        if(n == 0) 
        {
            cout << "mkfifo success!" << endl;
        }
        else
        {
            cout << "mkfifo failed! errno: " << errno << "errdesc: " << strerror(errno) << endl; 
        }
    }

    ~Fifo() 
    {
        int n = unlink(Path); //删除命名管道
        if(n == 0)
        {
            cout << "remove file success!" << endl;
        }
        else
        {
            cout << "remove file failed! errno: " << errno << "errdesc: " << strerror(errno) << endl; 
        }

    }

private:
    string _path;
};